package category;

import java.io.IOException;

import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

import yxnote.Category;
import yxnote.PMF;

public class Update extends HttpServlet{
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String id = req.getParameter("id");
        Key key = KeyFactory.createKey(Category.class.getSimpleName(), Long.valueOf(id));
        String name = req.getParameter("name");
        PersistenceManager pm = PMF.get().getPersistenceManager();
        try {
            Category category = pm.getObjectById(Category.class, key);
            category.setName(name);
        } finally {
            pm.close();
        }

        resp.sendRedirect("/category/index.jsp");
    }
}